<?php

class Admin_BlogController extends Zend_Controller_Action {

    public function init() {
        $this->view->headTitle('zendblog')->headTitle('admin')->setSeparator(' :: ');
        $this->view->title = 'admin';
    }

    public function createAction() {
        if ($this->view->hasBlog(Zend_Auth::getInstance()->getIdentity()->username)) {
            $this->view->hasBlog = true;
        } else {
            $blogForm = new Application_Form_Blog();
            if (!$this->getRequest()->isPost()) {
                $this->view->blogForm = $blogForm;
                return;
            } elseif (!$blogForm->isValid($_POST)) {
                $this->view->isInvalid = true;
                $this->view->blogForm = $blogForm;
                return;
            }
            $tableBlogs = new Application_Model_DbTable_Blogs();
            $data = array(
                'title' => $blogForm->getValue('title'),
                'user_id' => Zend_Auth::getInstance()->getIdentity()->id,
            );
            $tableBlogs->insert($data);
            $this->_forward('index', 'account');
        }
    }

}

